Skip to content

Conversation

@koke
Copy link
Member

@koke koke commented Nov 14, 2022

Closes: #8112

Description

This PR tries to make the IAP logging clearer and shows any error purchasing as an alert in the debug view. This includes:

  • After a purchase, we call submitTransaction directly if the purchase was successful and verified. We don't reuse handleCompletedTransaction anymore and that method is reserved for the transaction listener. This means different logging for the interactive purchase and transaction listener so that hopefully we'll differentiate those better in the logs.
  • More explicit handling of pending and user canceled purchases as a specific error
  • Added descriptions for all store errors

Testing instructions

There are many different ways to test all the errors, but the simplest way to verify this:

  1. Go to Hub menu > IAP debug
  2. Tap on a product to purchase
  3. When the IAP flow is presented, tap outside to dismiss it
  4. See an alert saying the purchase was cancelled

Screenshots

Screen Shot 2022-11-14 at 16 23 49


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@koke koke added type: task An internally driven task. feature: in-app purchases Related to In-app purchases and subscriptions labels Nov 14, 2022
@koke koke added this to the 11.3 milestone Nov 14, 2022
@koke koke requested a review from toupper November 14, 2022 15:35
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 14, 2022

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr8113-8494efb on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@toupper
Copy link
Contributor

toupper commented Nov 14, 2022

The code looks great (just a non-blocker comment) and tests well when the user cancels the purchase. Thanks for that! Now we are able to communicate better what happened to the IAP interface client. 🎉

await transaction.finish()
case .userCancelled:
logInfo("User cancelled the purchase flow")
throw Errors.userCancelled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but userCancelled or pending doesn't look exactly as errors to me, more like a "result". We could mimic Apple behavior and instead of throw an error, return an enum PurchaseResult (or typealias?):

public enum PurchaseResult {

        /// The purchase succeeded with a `Transaction`.
        case success(VerificationResult<Transaction>)

        /// The user cancelled the purchase.
        case userCancelled

        /// The purchase is pending some user action.
        ///
        /// These purchases may succeed in the future, and the resulting `Transaction` will be
        /// delivered via `Transaction.updates`
        case pending
    }

However, I understand that throwing an error is easier to implement and probably to handle, so if you prefer to leave as it is it is fine for me as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Actually, purchaseProduct is already returning a PurchaseResult but I ended up turning those two cases into errors 🤦🏽

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed those errors in 8494efb and tested that cancelling a purchase doesn't show an alert, while a network error during purchase shows the alert.

@koke koke merged commit c79669d into trunk Nov 15, 2022
@koke koke deleted the issue/8112-improve-error-reporting branch November 15, 2022 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: in-app purchases Related to In-app purchases and subscriptions type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[In-app Purchases] Improve error reporting

4 participants